/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.uml_generator.model.impl;

import java.util.ArrayList;
import java.util.List;

import com.genia.toolbox.uml_generator.Constants;
import com.genia.toolbox.uml_generator.model.AttributeModel;
import com.genia.toolbox.uml_generator.model.OperationModel;

/**
 * this class represent the operation for model entities from the xmi file.
 */
public class OperationModelImpl
    extends AbstractObjectImpl
    implements OperationModel
{
  /**
   * the type that operation return.
   */
  private AttributeModel returnType = null;

  /**
   * list of paramaters associated to the operationModel.
   */
  private final List<AttributeModel> parameterModels = new ArrayList<AttributeModel>();

  /**
   * the body of the method.
   */
  private String body;

  /**
   * wether this method override another function or not.
   */
  private boolean override = false;



  /**
   * add a new parameter to this operation.
   * 
   * @param parameterModel
   *          the parameter to add
   * @see com.genia.toolbox.uml_generator.model.OperationModel#addParameterModels(AttributeModel)
   */
  public void addParameterModels(AttributeModel parameterModel)
  {

    this.parameterModels.add(parameterModel);

  }



  /**
   * getter for the body property.
   * 
   * @return the body
   */
  public String getBody()
  {
    if (body == null) {
      if (hasVoidReturnType()) {
        body = "";
      }
      else {
        body = "return " + getReturnType().getType().getDefaultValue() + ";";
      }
    }
    return body;
  }



  /**
   * returns the list of the parameters of this operation.
   * 
   * @return the list of the parameters of this operation
   * @see com.genia.toolbox.uml_generator.model.OperationModel#getParameterModels()
   */
  public List<AttributeModel> getParameterModels()
  {

    return parameterModels;
  }



  /**
   * getter for returnType property.
   * 
   * @return the returnType
   */
  public AttributeModel getReturnType()
  {
    return returnType;
  }



  /**
   * returns wether this method returns a value or not.
   * 
   * @return <code>true</code> if and only if this method does not return any
   *         value
   * @see com.genia.toolbox.uml_generator.model.OperationModel#hasVoidReturnType()
   */
  public boolean hasVoidReturnType()
  {
    return getReturnType().getType().getQualifiedName().equals(Constants.VOID_MODEL.getName());
  }



  /**
   * setter for the body property.
   * 
   * @param body
   *          the body to set
   */
  public void setBody(String body)
  {
    this.body = body;
  }



  /**
   * setter for returnType property.
   * 
   * @param returnType
   *          the returnType to set
   */
  public void setReturnType(AttributeModel returnType)
  {
    this.returnType = returnType;
  }



  /**
   * getter for the override property.
   * 
   * @return the override
   */
  public boolean isOverride()
  {
    return override;
  }



  /**
   * setter for the override property.
   * 
   * @param override
   *          the override to set
   */
  public void setOverride(boolean override)
  {
    this.override = override;
  }
}
